﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

// Token: 0x0200031C RID: 796
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(CapsuleCollider))]
public class Player : Micro
{
	// Token: 0x06001452 RID: 5202 RVA: 0x00085804 File Offset: 0x00083A04
	protected override void Awake()
	{
		this.isPlayer = true;
		base.Awake();
		this.myTransform = base.transform;
		this.CurrentState = new Player.State(this.DefaultState);
		this.baseHeight = 1.6f;
		base.gameObject.name = "Player Character";
		this.capsule.center = new Vector3(0f, 0.8f, 0f);
		this.capsule.radius = 0.3f;
		this.capsule.height = 1.6f;
		this.rbody = base.GetComponent<Rigidbody>();
		this.rbody.freezeRotation = true;
		this.rbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
		this.rbody.useGravity = false;
		this.rbody.interpolation = RigidbodyInterpolation.Interpolate;
		base.gameObject.layer = Layers.playerLayer;
		this.height = this.capsule.height;
		this.resizer = base.gameObject.GetComponent<ResizeCharacter>();
		if (this.resizer == null)
		{
			this.resizer = base.gameObject.AddComponent<ResizeCharacter>();
		}
		this.cameraTransform = Camera.main.transform;
		this.speedFloat = Animator.StringToHash("Speed");
		this.jumpBool = Animator.StringToHash("Jump");
		this.hFloat = Animator.StringToHash("H");
		this.vFloat = Animator.StringToHash("V");
		this.climbBool = Animator.StringToHash("Climbing");
		this.turnFloat = Animator.StringToHash("Turn");
		this.aimBool = Animator.StringToHash("Aiming");
		this.flyBool = Animator.StringToHash("Fly");
		this.groundedBool = Animator.StringToHash("Grounded");
		this.sprintFactor = this.sprintSpeed / this.runSpeed;
		AudioSource[] components = base.gameObject.GetComponents<AudioSource>();
		if (components.Length > 0)
		{
			foreach (AudioSource obj in components)
			{
				UnityEngine.Object.Destroy(obj);
			}
		}
		this.audioSource = base.gameObject.AddComponent<AudioSource>();
		this.audioSource.outputAudioMixerGroup = SoundManager.mg_micro;
		this.flySource = base.gameObject.AddComponent<AudioSource>();
		this.flySource.outputAudioMixerGroup = SoundManager.mg_windA;
		this.flySource.loop = true;
		this.flySource.spatialBlend = 0f;
		this.flySource.dopplerLevel = 0f;
		this.flySource.volume = 0f;
		SoundManager.SetSoundClip(this.flySource, SoundManager.This.flySound);
		this.raygunArmingSource = base.gameObject.AddComponent<AudioSource>();
		this.raygunArmingSource.outputAudioMixerGroup = SoundManager.mg_raygun;
		this.raygunArmingSource.loop = false;
		this.raygunArmingSource.spatialBlend = 0f;
		this.raygunArmingSource.dopplerLevel = 0f;
		this.raygunArmingSource.volume = 0f;
		SoundManager.SetSoundClip(this.raygunArmingSource, SoundManager.This.playerRaygunArmingSound);
		if (this.playerIk == null)
		{
			this.playerIk = base.gameObject.AddComponent<PlayerIK>();
		}
		this.referenceTransform = new GameObject("Reference Transform", new Type[]
		{
			typeof(CameraReference)
		}).transform;
		if (!this.isGiantess)
		{
			this.shootCameraTarget = new GameObject("Shoot Camera Target");
			this.shootCameraTarget.transform.parent = base.transform;
			this.UpdateShooterTargetPosition();
			if (this.anim != null && this.lookController == null)
			{
				this.diffAngle = Vector3.Angle(base.transform.forward, this.anim.GetBoneTransform(HumanBodyBones.Head).forward);
				if (Mathf.Abs(this.diffAngle) > 5f)
				{
					this.lookController = base.gameObject.AddComponent<ComplexMicroLookAtController>();
				}
				else
				{
					this.lookController = base.gameObject.AddComponent<MicroLookAtController>();
				}
			}
		}
	}

	// Token: 0x06001453 RID: 5203 RVA: 0x00085C1C File Offset: 0x00083E1C
	private void Start()
	{
		this.playerCamera = PlayerCamera.instance;
		this.raygunObj = UnityEngine.Object.Instantiate<GameObject>((GameObject)Resources.Load("Raygun/playerRaygunPrefab"));
		this.raygun = this.raygunObj.GetComponent<PlayerRaygun>();
		this.raygun.SetCamera(this.playerCamera.getMainCamera());
		this.handObj = this.raygunObj;
		this.handObj.SetActive(false);
		base.StartCoroutine(this.SetupTPSRaygun());
	}

	// Token: 0x06001454 RID: 5204 RVA: 0x00085C9C File Offset: 0x00083E9C
	protected override void OnDestroy()
	{
		UnityEngine.Object.Destroy(this.audioSource);
		UnityEngine.Object.Destroy(this.flySource);
		UnityEngine.Object.Destroy(this.playerIk);
		UnityEngine.Object.Destroy(base.gameObject.GetComponent<Destructor>());
		UnityEngine.Object.Destroy(this.referenceTransform.gameObject);
		UnityEngine.Object.Destroy(this.handObj);
		UnityEngine.Object.Destroy(this.shootCameraTarget);
		base.OnDestroy();
	}

	// Token: 0x06001455 RID: 5205 RVA: 0x00085D08 File Offset: 0x00083F08
	public override void OnStartAuthority()
	{
		GameController.Instance.SetPlayerInstance(this);
		PlayerCamera component = Camera.main.GetComponent<PlayerCamera>();
		component.SetCameraTarget(base.transform);
		this.resizer.ChangeScale(GameController.startingSize);
		GameController.Instance.OnPlayerStart();
	}

	// Token: 0x06001456 RID: 5206 RVA: 0x00085D54 File Offset: 0x00083F54
	private void UpdateReference()
	{
		if (this.referenceTransform.parent != base.transform.parent)
		{
			this.referenceTransform.SetParent(base.transform.parent);
		}
		Vector3 vector = (!this.climbing) ? Vector3.up : base.transform.up;
		Vector3 forward = Vector3.ProjectOnPlane(this.referenceTransform.forward, vector);
		Quaternion b = Quaternion.LookRotation(forward, vector);
		this.referenceTransform.rotation = Quaternion.Slerp(this.referenceTransform.rotation, b, Time.deltaTime * 4f);
	}

	// Token: 0x06001457 RID: 5207 RVA: 0x00085DF9 File Offset: 0x00083FF9
	private void LateUpdate()
	{
		if (!base.hasAuthority)
		{
			return;
		}
	}

	// Token: 0x06001458 RID: 5208 RVA: 0x00085E08 File Offset: 0x00084008
	private void Update()
	{
		if (!base.hasAuthority)
		{
			return;
		}
		if (GameController.playerInputEnabled)
		{
			this.horizontalInput = Input.GetAxis(ButtonInput.HorizontalAxis);
			this.verticalInput = Input.GetAxis(ButtonInput.VerticalAxis);
			if (Input.GetKeyDown(KeyCode.RightShift))
			{
				this.autowalk = !this.autowalk;
			}
			if (this.autowalk)
			{
				this.verticalInput = 1f;
			}
			if (Input.GetButton(ButtonInput.LookBack) && !this.aim)
			{
				this.horizontalInput *= -1f;
				this.verticalInput *= -1f;
			}
			if (Input.GetButtonDown(ButtonInput.Fly))
			{
				this.fly = !this.fly;
				this.setClimb(false);
				if (this.anim.HasState(0, this.speedFloat))
				{
					this.anim.SetFloat(this.speedFloat, 1f);
				}
				if (this.fly && base.transform.parent != null)
				{
					base.Invoke("UnparentWhileFlyng", 1f);
				}
			}
			if (Input.GetButtonDown(ButtonInput.Climb) && !this.fly && !this.aim)
			{
				this.setClimb(!this.climbing);
			}
			this.sprint = Input.GetButton(ButtonInput.Sprint);
			if (Input.GetButtonDown(ButtonInput.Aim))
			{
				if (this.aim)
				{
					this.DisableAim();
				}
				else
				{
					this.SetupAim();
				}
			}
			if (this.aim)
			{
				this.playerIk.GetAimIk().solver.target = this.raygun.GetAimTargetTransform();
				if (Input.GetButtonDown(ButtonInput.Fire))
				{
					this.raygun.StartFiring();
				}
				else if (Input.GetButtonUp(ButtonInput.Fire))
				{
					this.raygun.StopFiring();
				}
				if (Input.GetButtonUp(ButtonInput.SwitchFiringMode))
				{
					this.raygun.SwitchFiringMode();
				}
			}
			if (Input.GetButtonDown(ButtonInput.ToggleWalk))
			{
				this.walk = !this.walk;
			}
			this.jumpHold = Input.GetButton(ButtonInput.Jump);
			if (this.jumpHold && Input.GetButtonDown(ButtonInput.Jump))
			{
				this.jump = true;
			}
			if (this.IsFlying() && !Player.vrMode)
			{
				if (Input.GetButtonDown(ButtonInput.Sprint))
				{
					if (Time.time < this.lastShiftTime + this.timeBetweenShifts)
					{
						this.superFlySpeed = true;
					}
					else
					{
						this.lastShiftTime = Time.time;
					}
				}
			}
			else
			{
				this.superFlySpeed = false;
			}
			this.isMoving = ((double)Mathf.Abs(this.horizontalInput) > 0.1 || (double)Mathf.Abs(this.verticalInput) > 0.1);
			this.camForwardDirection = this.cameraTransform.TransformDirection(Vector3.forward);
			if (Input.GetButtonDown(ButtonInput.Enter) && ObjectManager.Instance.vehicles.Count > 0)
			{
				VehicleEnterExit vehicleEnterExit = null;
				float num = 10000f;
				foreach (VehicleEnterExit vehicleEnterExit2 in ObjectManager.Instance.vehicles)
				{
					if (!(vehicleEnterExit2 == null))
					{
						float sqrMagnitude = (base.transform.position - vehicleEnterExit2.transform.position).sqrMagnitude;
						if (!vehicleEnterExit || sqrMagnitude < num)
						{
							vehicleEnterExit = vehicleEnterExit2;
							num = sqrMagnitude;
						}
					}
				}
				if (vehicleEnterExit)
				{
					vehicleEnterExit.EnterVehicle();
				}
			}
		}
		else
		{
			this.horizontalInput = 0f;
			this.verticalInput = 0f;
		}
		if (this.rbody.interpolation == RigidbodyInterpolation.Interpolate && this.myTransform.parent != null)
		{
			this.rbody.interpolation = RigidbodyInterpolation.None;
		}
		else if (this.rbody.interpolation == RigidbodyInterpolation.None && this.myTransform.parent == null)
		{
			this.rbody.interpolation = RigidbodyInterpolation.Interpolate;
		}
	}

	// Token: 0x06001459 RID: 5209 RVA: 0x00086288 File Offset: 0x00084488
	private void UnparentWhileFlyng()
	{
		if (this.fly && base.transform.parent != null)
		{
			base.transform.SetParent(null);
		}
	}

	// Token: 0x0600145A RID: 5210 RVA: 0x000862B8 File Offset: 0x000844B8
	private void setClimb(bool val)
	{
		this.climbing = val;
		this.anim.SetBool(this.climbBool, this.climbing);
		float num = 1f;
		if (this.climbing)
		{
			num = 0.3f;
		}
		this.capsule.height = this.height * num;
		this.capsule.center = Vector3.up * this.height * num * 0.5f;
	}

	// Token: 0x0600145B RID: 5211 RVA: 0x00086338 File Offset: 0x00084538
	private void FixedUpdate()
	{
		if (!base.hasAuthority)
		{
			return;
		}
		this.CurrentState();
		this.UpdateReference();
	}

	// Token: 0x0600145C RID: 5212 RVA: 0x00086358 File Offset: 0x00084558
	private void DefaultState()
	{
		if (this.anim.runtimeAnimatorController != IOManager.Instance.playerAnimatorController || this.ai.IsEnabled())
		{
			this.CurrentState = new Player.State(this.AutoState);
			if (this.climbing)
			{
				this.setClimb(false);
			}
			return;
		}
		this.anim.SetFloat(this.hFloat, this.horizontalInput);
		this.anim.SetFloat(this.vFloat, this.verticalInput);
		this.anim.SetFloat(this.turnFloat, 0f);
		this.anim.SetBool(this.flyBool, this.fly);
		this.gravity.enabled = !this.fly;
		this.anim.SetBool(this.groundedBool, base.IsOnGround() || base.IsOnGiantess());
		this.FlySound();
		if (this.fly)
		{
			this.FlyManagement(this.horizontalInput, this.verticalInput);
			this.jump = false;
		}
		else if (this.climbing)
		{
			this.ClimbManagement(this.horizontalInput, this.verticalInput, this.sprint);
			this.jump = false;
		}
		else
		{
			this.MovementManagement(this.horizontalInput, this.verticalInput, this.sprint);
			this.JumpManagement();
		}
		this.TurnFPSCamera();
	}

	// Token: 0x0600145D RID: 5213 RVA: 0x000864D0 File Offset: 0x000846D0
	private void ClimbManagement(float horizontal, float vertical, bool sprinting)
	{
		float d = Physics.gravity.y * base.Scale * 1.5f;
		RaycastHit raycastHit;
		bool flag = Physics.Raycast(base.transform.position + base.transform.up * 0.1f * base.Scale, base.transform.forward, out raycastHit, 1f * base.Scale);
		if (!flag)
		{
			flag = Physics.Raycast(base.transform.position + base.transform.up * 0.1f * base.Scale, -base.transform.up, out raycastHit, 2f * base.Scale);
		}
		this.gravity.enabled = !flag;
		if (flag)
		{
			this.targetDir = raycastHit.normal;
		}
		else
		{
			this.targetDir = Vector3.up;
		}
		Vector3 vector;
		if (this.isMoving && PlayerCamera.instance.firstPersonMode)
		{
			vector = this.GetCameraForward().normalized;
		}
		else
		{
			vector = this.myTransform.forward;
		}
		Quaternion quaternion = Quaternion.LookRotation(Vector3.ProjectOnPlane(vector, this.targetDir), this.targetDir);
		quaternion = Quaternion.Slerp(base.transform.rotation, quaternion, this.climbRotationSmooth * Time.fixedDeltaTime);
		quaternion *= Quaternion.Euler(0f, horizontal * this.climbTurnSpeed, 0f);
		this.rbody.MoveRotation(quaternion);
		this.rbody.AddForce(this.targetDir * d);
		if (this.isMoving)
		{
			this.climbSpeed = 150f;
			if (Player.vrMode)
			{
				this.climbSpeed = 50f;
			}
			else if (this.sprint)
			{
				this.climbSpeed *= 2f;
			}
			this.anim.SetFloat(this.speedFloat, vertical * this.climbSpeed / 80f);
			this.rbody.AddForce(vector * vertical * this.climbSpeed * base.Scale);
		}
		else
		{
			this.anim.SetFloat(this.speedFloat, 0f);
		}
	}

	// Token: 0x0600145E RID: 5214 RVA: 0x00086740 File Offset: 0x00084940
	private void FlyManagement(float horizontal, float vertical)
	{
		float d = this.flySpeed;
		if (this.superFlySpeed)
		{
			d = this.superSpeed;
		}
		float num = 1f;
		if (this.sprint)
		{
			num *= this.sprintFactor * 4f;
		}
		Vector3 a = this.Rotating(horizontal, vertical);
		if (this.jumpHold)
		{
			a += new Vector3(0f, 1f, 0f);
		}
		if (this.isMoving || this.jumpHold)
		{
			this.rbody.AddForce(a * d * base.Scale * 100f * num);
			this.anim.SetFloat(this.speedFloat, this.walkSpeed, this.speedDampTime, Time.fixedDeltaTime * 3f);
		}
	}

	// Token: 0x0600145F RID: 5215 RVA: 0x00086820 File Offset: 0x00084A20
	private void JumpManagement()
	{
		if (this.rbody.velocity.y < 10f)
		{
			this.anim.SetBool(this.jumpBool, false);
			if (this.timeToNextJump > 0f)
			{
				this.timeToNextJump -= Time.fixedDeltaTime;
			}
		}
		if (this.jump)
		{
			this.jump = false;
			if (this.timeToNextJump <= 0f)
			{
				this.anim.SetBool(this.jumpBool, true);
				this.rbody.velocity = new Vector3(0f, this.jumpHeight * base.Scale, 0f);
				this.timeToNextJump = this.jumpCooldown;
			}
		}
	}

	// Token: 0x06001460 RID: 5216 RVA: 0x000868E8 File Offset: 0x00084AE8
	private void MovementManagement(float horizontal, float vertical, bool sprinting)
	{
		if (this.isMoving)
		{
			if (sprinting && !Player.vrMode)
			{
				this.speed = this.sprintSpeed;
			}
			else if ((!this.walk && !Player.vrMode) || (this.sprint && Player.vrMode))
			{
				this.speed = this.runSpeed;
			}
			else
			{
				this.speed = this.walkSpeed;
			}
			this.anim.SetFloat(this.speedFloat, this.speed, this.speedDampTime, Time.fixedDeltaTime);
		}
		else
		{
			this.speed = 0f;
			this.anim.SetFloat(this.speedFloat, 0f, this.speedDampTime / 4f, Time.fixedDeltaTime);
		}
		if (PlayerCamera.instance.firstPersonMode && this.isMoving)
		{
			Vector3 forward = this.GetCameraForward() * vertical + this.playerCamera.transform.parent.right * horizontal;
			if (!this.aim)
			{
				this.rbody.MoveRotation(Quaternion.LookRotation(forward));
			}
		}
		else
		{
			this.Rotating(horizontal, vertical);
		}
		this.rbody.AddForce(this.myTransform.forward * this.speed * base.AccurateScale);
	}

	// Token: 0x06001461 RID: 5217 RVA: 0x00086A60 File Offset: 0x00084C60
	private void SetupAim()
	{
		if (this.aim || base.isCrushed)
		{
			return;
		}
		this.aim = true;
		if (this.climbing)
		{
			this.setClimb(false);
		}
		this.rbody.MoveRotation(Quaternion.LookRotation(this.GetCameraForward()));
		this.handObj.SetActive(true);
		this.anim.SetBool(this.aimBool, this.aim);
		this.anim.SetFloat(this.speedFloat, 0f);
		this.playerIk.GetAimIk().enabled = true;
		SoundManager.SetSoundClip(this.raygunArmingSource, SoundManager.This.playerRaygunArmingSound);
		this.raygunArmingSource.volume = 1f;
		this.raygunArmingSource.Play();
		base.StartCoroutine(this.setAimIkTransform());
	}

	// Token: 0x06001462 RID: 5218 RVA: 0x00086B3C File Offset: 0x00084D3C
	private IEnumerator setAimIkTransform()
	{
		yield return null;
		this.playerCamera.SwitchShooterMode(true);
		this.playerIk.GetAimIk().solver.transform = this.raygun.getFiringPoint();
		yield break;
	}

	// Token: 0x06001463 RID: 5219 RVA: 0x00086B58 File Offset: 0x00084D58
	public void DisableAim()
	{
		if (!this.aim)
		{
			return;
		}
		this.aim = false;
		this.playerCamera.SwitchShooterMode(false);
		this.handObj.SetActive(false);
		this.anim.SetBool(this.aimBool, this.aim);
		this.playerIk.GetAimIk().enabled = false;
		SoundManager.SetSoundClip(this.raygunArmingSource, SoundManager.This.playerRaygunDisarmingSound);
		this.raygunArmingSource.Play();
	}

	// Token: 0x06001464 RID: 5220 RVA: 0x00086BD8 File Offset: 0x00084DD8
	public void SwitchPerspective()
	{
		if (PlayerCamera.instance.firstPersonMode)
		{
			base.StartCoroutine(this.SetupFPSRaygun());
			this.CenterShooterTargetPosition();
		}
		else
		{
			base.StartCoroutine(this.SetupTPSRaygun());
			this.UpdateShooterTargetPosition();
		}
	}

	// Token: 0x06001465 RID: 5221 RVA: 0x00086C14 File Offset: 0x00084E14
	private IEnumerator SetupTPSRaygun()
	{
		yield return null;
		yield return null;
		if (this.anim.GetBoneTransform(HumanBodyBones.RightMiddleIntermediate) != null && this.anim.GetBoneTransform(HumanBodyBones.RightThumbIntermediate) != null)
		{
			Vector3 position = this.anim.GetBoneTransform(HumanBodyBones.RightMiddleIntermediate).position;
			Vector3 position2 = this.anim.GetBoneTransform(HumanBodyBones.RightThumbIntermediate).position;
			this.raygunObj.transform.position = new Vector3(position2.x, position2.y, position.z);
		}
		else
		{
			this.raygunObj.transform.position = this.anim.GetBoneTransform(HumanBodyBones.RightHand).position;
		}
		this.raygunObj.transform.SetParent(this.anim.GetBoneTransform(HumanBodyBones.RightHand));
		if (!this.raygunInitialized)
		{
			this.raygunObj.transform.rotation = Quaternion.identity;
			this.raygunObj.transform.rotation = Quaternion.Euler(90f, base.transform.rotation.eulerAngles.y, 0f);
			this.raygunInitialized = true;
			this.thirdPersonRaygunRot = this.raygunObj.transform.localRotation;
		}
		else
		{
			this.raygunObj.transform.localRotation = this.thirdPersonRaygunRot;
		}
		this.raygun.SetFirstPersonMode(false);
		yield break;
	}

	// Token: 0x06001466 RID: 5222 RVA: 0x00086C30 File Offset: 0x00084E30
	private IEnumerator SetupFPSRaygun()
	{
		yield return null;
		yield return null;
		this.raygunObj.transform.SetParent(this.playerCamera.transform);
		this.raygunObj.transform.localPosition = new Vector3(0f, -0.2f, -0.15f);
		this.raygunObj.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
		this.raygun.SetFirstPersonMode(true);
		yield break;
	}

	// Token: 0x06001467 RID: 5223 RVA: 0x00086C4C File Offset: 0x00084E4C
	private void TurnFPSCamera()
	{
		if (this.climbing || true)
		{
			return;
		}
		Vector3 cameraForward = this.GetCameraForward();
		this.rbody.rotation = Quaternion.LookRotation(cameraForward, base.transform.up);
	}

	// Token: 0x06001468 RID: 5224 RVA: 0x00086C90 File Offset: 0x00084E90
	private Vector3 GetCameraForward()
	{
		Vector3 direction = base.transform.InverseTransformDirection(this.playerCamera.transform.forward);
		direction.y = 0f;
		return base.transform.TransformDirection(direction);
	}

	// Token: 0x06001469 RID: 5225 RVA: 0x00086CD4 File Offset: 0x00084ED4
	private Vector3 GetCameraRight()
	{
		Vector3 direction = base.transform.InverseTransformDirection(this.playerCamera.transform.forward);
		direction.y = 0f;
		return base.transform.TransformDirection(direction);
	}

	// Token: 0x0600146A RID: 5226 RVA: 0x00086D18 File Offset: 0x00084F18
	private Vector3 Rotating(float horizontal, float vertical)
	{
		if (!this.fly)
		{
			this.camForwardDirection.y = 0f;
		}
		this.camForwardDirection = this.camForwardDirection.normalized;
		Vector3 a = new Vector3(this.camForwardDirection.z, 0f, -this.camForwardDirection.x);
		Vector3 vector;
		if (this.aim)
		{
			vector = this.camForwardDirection;
		}
		else
		{
			vector = this.camForwardDirection * vertical + a * horizontal;
		}
		if (this.CurrentState != new Player.State(this.AutoState))
		{
			Vector3 vector2 = base.transform.InverseTransformDirection(vector);
			vector2 = Vector3.ProjectOnPlane(vector2, Vector3.up);
			this.turnAngle = Mathf.Lerp(this.turnAngle, Mathf.Atan2(vector2.x, vector2.z), Time.deltaTime * 2f);
			this.anim.SetFloat(this.turnFloat, this.turnAngle);
		}
		float num = this.turnSmoothing;
		if (this.isMoving && vector != Vector3.zero)
		{
			Quaternion quaternion = Quaternion.LookRotation(vector, Vector3.up);
			if (this.fly)
			{
				quaternion *= Quaternion.Euler(90f, 0f, 0f);
			}
			if (this.aim)
			{
				this.rbody.MoveRotation(quaternion);
			}
			else
			{
				Quaternion rot = Quaternion.Slerp(this.rbody.rotation, quaternion, num * Time.fixedDeltaTime);
				this.rbody.MoveRotation(rot);
			}
		}
		if (this.aim)
		{
			this.rbody.MoveRotation(Quaternion.LookRotation(vector, Vector3.up));
			vector = this.camForwardDirection * vertical + a * horizontal;
		}
		if ((double)Mathf.Abs(this.horizontalInput) <= 0.9 && (double)Mathf.Abs(this.verticalInput) <= 0.9)
		{
			this.VerticalFix();
		}
		return vector;
	}

	// Token: 0x0600146B RID: 5227 RVA: 0x00086F30 File Offset: 0x00085130
	private void SnapToCameraForward(float horizontal, float vertical)
	{
		this.camForwardDirection = this.camForwardDirection.normalized;
		Vector3 vector = new Vector3(this.camForwardDirection.z, 0f, -this.camForwardDirection.x);
		Vector3 forward = this.camForwardDirection;
		Quaternion rot = Quaternion.LookRotation(forward, Vector3.up);
		this.rbody.MoveRotation(rot);
	}

	// Token: 0x0600146C RID: 5228 RVA: 0x00086F90 File Offset: 0x00085190
	private void VerticalFix()
	{
		if (this.locked || this.isDead)
		{
			return;
		}
		Vector3 forward = this.myTransform.forward;
		if (forward.y == 0f)
		{
			return;
		}
		forward.y = 0f;
		Quaternion quaternion = Quaternion.LookRotation(forward);
		Quaternion rotation = this.rbody.rotation;
		if (rotation == quaternion)
		{
			return;
		}
		Quaternion rot = Quaternion.Slerp(rotation, quaternion, this.turnSmoothing * Time.deltaTime);
		this.rbody.MoveRotation(rot);
	}

	// Token: 0x0600146D RID: 5229 RVA: 0x0008701E File Offset: 0x0008521E
	public bool IsFlying()
	{
		return this.fly;
	}

	// Token: 0x0600146E RID: 5230 RVA: 0x00087026 File Offset: 0x00085226
	public bool IsAiming()
	{
		return this.walk && !this.fly;
	}

	// Token: 0x0600146F RID: 5231 RVA: 0x0008703F File Offset: 0x0008523F
	public bool isSprinting()
	{
		return this.sprint && !this.aim && this.isMoving;
	}

	// Token: 0x06001470 RID: 5232 RVA: 0x00087060 File Offset: 0x00085260
	public bool isClimbing()
	{
		return this.climbing;
	}

	// Token: 0x06001471 RID: 5233 RVA: 0x00087068 File Offset: 0x00085268
	public override void DestroyObject(bool recursive = true)
	{
		if (!base.gameObject.activeSelf)
		{
			base.SetActive(true);
			if (base.hasAuthority)
			{
				this.playerCamera.SetCameraTarget(base.transform);
			}
		}
		base.gameObject.transform.SetParent(null);
	}

	// Token: 0x06001472 RID: 5234 RVA: 0x000870BC File Offset: 0x000852BC
	public override void Crush(EntityBase entity, Micro.CollisionData collisionData)
	{
		if (!GlobalPreferences.CrushPlayerEnabled.value && this.isPlayer)
		{
			return;
		}
		if (entity != null && ((!GlobalPreferences.NpcMicroCrushingEnabled.value && entity.isMicro) || (!GlobalPreferences.NpcGtsCrushingEnabled.value && entity.isGiantess)))
		{
			return;
		}
		this.climbing = false;
		if (this.aim)
		{
			this.DisableAim();
		}
		if (collisionData != null)
		{
			base.Crush(entity, collisionData);
		}
		this.CurrentState = new Player.State(this.CrushedState);
	}

	// Token: 0x06001473 RID: 5235 RVA: 0x00087160 File Offset: 0x00085360
	private void LockedState()
	{
		if (this.jump || this.fly || this.climbing || !this.locked)
		{
			this.jump = false;
			this.fly = false;
			this.climbing = false;
			this.rbody.isKinematic = false;
			this.gravity.enabled = true;
			this.isDead = false;
			this.locked = false;
			this.CurrentState = new Player.State(this.DefaultState);
		}
		if (this.aim)
		{
			this.DisableAim();
		}
	}

	// Token: 0x06001474 RID: 5236 RVA: 0x000871F8 File Offset: 0x000853F8
	private void CrushedState()
	{
		if (this.jump || this.fly || this.climbing)
		{
			this.jump = false;
			this.fly = false;
			this.climbing = false;
			if (!base.IsStuck() || Input.GetKey(KeyCode.LeftShift) || UnityEngine.Random.value > GlobalPreferences.CrushStickChance.value)
			{
				this.StandUp();
			}
			else
			{
				this.anim.Play("Fall", 0, 0.2f);
			}
		}
	}

	// Token: 0x06001475 RID: 5237 RVA: 0x0008728A File Offset: 0x0008548A
	public override void StandUp()
	{
		if (this.CurrentState != new Player.State(this.CrushedState))
		{
			return;
		}
		this.CurrentState = new Player.State(this.DefaultState);
		base.StandUp();
	}

	// Token: 0x06001476 RID: 5238 RVA: 0x000872C4 File Offset: 0x000854C4
	private void AutoState()
	{
		if (this.jump || this.fly || this.climbing || !this.ai.IsIdle() || (this.anim.runtimeAnimatorController.name.Equals("GTSAnimator") && (this.horizontalInput != 0f || this.verticalInput != 0f)))
		{
			if (!this.ai.IsIdle())
			{
				this.ai.behaviorController.StopMainBehavior();
			}
			if (this.climbing)
			{
				this.climbing = false;
			}
			this.ai.DisableAI();
			this.ai.actionManager.ClearAll();
			AnimationManager.SetAnimatorController(this.anim, IOManager.Instance.playerAnimatorController);
			this.CurrentState = new Player.State(this.DefaultState);
		}
		if (this.ai.IsIdle())
		{
			this.Rotating(this.horizontalInput, this.verticalInput);
		}
	}

	// Token: 0x06001477 RID: 5239 RVA: 0x000873D8 File Offset: 0x000855D8
	public override void OnStep(AnimationEvent e)
	{
		float magnitude = (e.floatParameter != 0f) ? e.floatParameter : 1f;
		EventManager.SendEvent(new StepEvent(this, base.transform.position, magnitude, e.intParameter));
		this.audioSource.pitch = 0.9f;
		this.audioSource.volume = 1f;
		this.audioSource.spatialBlend = 1f;
		this.audioSource.dopplerLevel = 0f;
		this.audioSource.minDistance = 0.5f * base.Scale;
		this.audioSource.maxDistance = 10f * base.Scale;
		this.audioSource.PlayOneShot(SoundManager.This.GetPlayerFootstepSound());
	}

	// Token: 0x06001478 RID: 5240 RVA: 0x000874A8 File Offset: 0x000856A8
	public override void Lock()
	{
		base.Lock();
		this.anim.SetFloat(this.speedFloat, 0f);
		if (this.CurrentState != new Player.State(this.LockedState))
		{
			this.CurrentState = new Player.State(this.LockedState);
		}
	}

	// Token: 0x06001479 RID: 5241 RVA: 0x00087500 File Offset: 0x00085700
	public void FlySound()
	{
		float b = 0.2f;
		float b2 = 1f;
		if (!this.fly)
		{
			b = 0f;
		}
		else if (!this.isMoving)
		{
			b = 0.05f;
		}
		else if (this.superFlySpeed && this.sprint)
		{
			b = 1f;
			b2 = 3f;
		}
		else if (this.sprint || (this.superFlySpeed && !this.sprint))
		{
			b = 0.5f;
			b2 = 1.5f;
		}
		this.flySource.volume = Mathf.Lerp(this.flySource.volume, b, 2f * Time.deltaTime);
		this.flySource.pitch = Mathf.Lerp(this.flySource.pitch, b2, Time.deltaTime);
	}

	// Token: 0x0600147A RID: 5242 RVA: 0x000875E1 File Offset: 0x000857E1
	protected override void HandleGiantessContact()
	{
		if (this.fly && base.transform.parent == null)
		{
			this.fly = false;
		}
	}

	// Token: 0x0600147B RID: 5243 RVA: 0x0008760B File Offset: 0x0008580B
	public void UpdateShooterTargetPosition()
	{
		this.shootCameraTarget.transform.localPosition = new Vector3(GlobalPreferences.AimTargetDist.value * -1f, 0f, 0.5f);
	}

	// Token: 0x0600147C RID: 5244 RVA: 0x0008763C File Offset: 0x0008583C
	private void CenterShooterTargetPosition()
	{
		this.shootCameraTarget.transform.localPosition = new Vector3(0f, 0f, 0.5f);
	}

	// Token: 0x0600147D RID: 5245 RVA: 0x00087664 File Offset: 0x00085864
	public void LookAt(EntityBase target)
	{
		if (this.anim != null && this.lookController != null && !base.isCrushed)
		{
			if (!this.lookController.enabled)
			{
				this.lookController.enabled = true;
			}
			this.lookController.LookAt(target);
		}
	}

	// Token: 0x0600147E RID: 5246 RVA: 0x000876C6 File Offset: 0x000858C6
	public PlayerRaygun GetRaygun()
	{
		return this.raygun;
	}

	// Token: 0x06001480 RID: 5248 RVA: 0x00002973 File Offset: 0x00000B73
	private void UNetVersion()
	{
	}

	// Token: 0x06001481 RID: 5249 RVA: 0x000876D0 File Offset: 0x000858D0
	public override bool OnSerialize(NetworkWriter writer, bool forceAll)
	{
		bool flag = base.OnSerialize(writer, forceAll);
		bool flag2;
		return flag2 || flag;
	}

	// Token: 0x06001482 RID: 5250 RVA: 0x000843B1 File Offset: 0x000825B1
	public override void OnDeserialize(NetworkReader reader, bool initialState)
	{
		base.OnDeserialize(reader, initialState);
	}

	// Token: 0x0400174E RID: 5966
	public static bool vrMode;

	// Token: 0x0400174F RID: 5967
	public float walkSpeed = 0.2f;

	// Token: 0x04001750 RID: 5968
	public float runSpeed = 0.8f;

	// Token: 0x04001751 RID: 5969
	public float sprintSpeed = 3f;

	// Token: 0x04001752 RID: 5970
	public float flySpeed = 8f;

	// Token: 0x04001753 RID: 5971
	public float turnSmoothing = 4f;

	// Token: 0x04001754 RID: 5972
	public float speedDampTime = 0.4f;

	// Token: 0x04001755 RID: 5973
	public float climbTurnSpeed = 1.5f;

	// Token: 0x04001756 RID: 5974
	public float climbRotationSmooth = 4f;

	// Token: 0x04001757 RID: 5975
	public float climbSpeed = 70f;

	// Token: 0x04001758 RID: 5976
	public float jumpHeight = 7f;

	// Token: 0x04001759 RID: 5977
	private float jumpCooldown = 1f;

	// Token: 0x0400175A RID: 5978
	private float height;

	// Token: 0x0400175B RID: 5979
	private float timeToNextJump;

	// Token: 0x0400175C RID: 5980
	private float speed;

	// Token: 0x0400175D RID: 5981
	private int speedFloat;

	// Token: 0x0400175E RID: 5982
	private int jumpBool;

	// Token: 0x0400175F RID: 5983
	private int hFloat;

	// Token: 0x04001760 RID: 5984
	private int vFloat;

	// Token: 0x04001761 RID: 5985
	private int turnFloat;

	// Token: 0x04001762 RID: 5986
	private int flyBool;

	// Token: 0x04001763 RID: 5987
	private int groundedBool;

	// Token: 0x04001764 RID: 5988
	private int climbBool;

	// Token: 0x04001765 RID: 5989
	private int aimBool;

	// Token: 0x04001766 RID: 5990
	private Transform cameraTransform;

	// Token: 0x04001767 RID: 5991
	private ResizeCharacter resizer;

	// Token: 0x04001768 RID: 5992
	private PlayerCamera playerCamera;

	// Token: 0x04001769 RID: 5993
	private float horizontalInput;

	// Token: 0x0400176A RID: 5994
	private float verticalInput;

	// Token: 0x0400176B RID: 5995
	public bool aim;

	// Token: 0x0400176C RID: 5996
	private bool sprint;

	// Token: 0x0400176D RID: 5997
	private bool jump;

	// Token: 0x0400176E RID: 5998
	private bool jumpHold;

	// Token: 0x0400176F RID: 5999
	public bool isMoving;

	// Token: 0x04001770 RID: 6000
	private bool climbing;

	// Token: 0x04001771 RID: 6001
	private bool fly;

	// Token: 0x04001772 RID: 6002
	private float sprintFactor;

	// Token: 0x04001773 RID: 6003
	private bool walk;

	// Token: 0x04001774 RID: 6004
	private Vector3 targetDir;

	// Token: 0x04001775 RID: 6005
	private float turnAngle;

	// Token: 0x04001776 RID: 6006
	public bool autowalk;

	// Token: 0x04001777 RID: 6007
	private Vector3 camForwardDirection;

	// Token: 0x04001778 RID: 6008
	private AudioSource audioSource;

	// Token: 0x04001779 RID: 6009
	private AudioSource flySource;

	// Token: 0x0400177A RID: 6010
	private AudioSource raygunArmingSource;

	// Token: 0x0400177B RID: 6011
	public float superSpeed = 1000f;

	// Token: 0x0400177C RID: 6012
	private bool superFlySpeed;

	// Token: 0x0400177D RID: 6013
	private float lastShiftTime;

	// Token: 0x0400177E RID: 6014
	private float timeBetweenShifts = 0.2f;

	// Token: 0x0400177F RID: 6015
	private Player.State CurrentState;

	// Token: 0x04001780 RID: 6016
	public GameObject shootCameraTarget;

	// Token: 0x04001781 RID: 6017
	private GameObject raygunObj;

	// Token: 0x04001782 RID: 6018
	private PlayerRaygun raygun;

	// Token: 0x04001783 RID: 6019
	private bool raygunInitialized;

	// Token: 0x04001784 RID: 6020
	private Quaternion thirdPersonRaygunRot;

	// Token: 0x04001785 RID: 6021
	public Transform referenceTransform;

	// Token: 0x04001786 RID: 6022
	private PlayerIK playerIk;

	// Token: 0x04001787 RID: 6023
	private GameObject handObj;

	// Token: 0x04001788 RID: 6024
	public MicroLookAtController lookController;

	// Token: 0x04001789 RID: 6025
	private float diffAngle;

	// Token: 0x0200031D RID: 797
	// (Invoke) Token: 0x06001484 RID: 5252
	private delegate void State();
}
